#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/slab.h>

#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/regulator/consumer.h>
#include <linux/platform_device.h>

#define TAG "of_reg"
#define LOG_INF(format, args...)    pr_info(TAG "[%s:%d] " format, __func__, __LINE__, ##args)
#define LOG_ERR(format, args...)    pr_err(TAG "[%s:%d] " format, __func__, __LINE__, ##args)


static int dts_demo_remove(struct platform_device *pdev)
{
	LOG_INF("enter");
	return 0;
}

void parse_regulator(struct device *dev)
{
	struct regulator *mmciv, *fixed2v8;
	int err = 0;

	mmciv = devm_regulator_get(dev, "gpio");
	fixed2v8 = devm_regulator_get(dev, "fix");

	if(IS_ERR(fixed2v8)){
		LOG_ERR("get fix reggulator fail, err=%ld\n", PTR_ERR(fixed2v8));
	}else{
		err = regulator_enable(fixed2v8);
	}

	if(IS_ERR(mmciv)){
		LOG_ERR("get gpio reggulator fail, err=%ld\n", PTR_ERR(mmciv));
	}else{
		err = regulator_set_voltage(mmciv, 1800000, 1800000);
		err = regulator_enable(mmciv);
	}
}


static int dts_demo_probe(struct platform_device *pdev)
{
	LOG_INF("enter");
	parse_regulator(&pdev->dev);
	return 0;
}

static const struct of_device_id dts_demo_match[] = {
	{ .compatible = "rockchip,comsumer",},
	{}
};

static struct platform_driver dts_demo_driver = {
	.probe = dts_demo_probe,
    .remove = dts_demo_remove,
    .driver = {
        .name = TAG,
 //       .module = THIS_MODULE,
        .of_match_table = dts_demo_match,
    },
};

static int __init demo_init(void)
{
	int err = 0;
	LOG_INF("enter");
	//parse_gpio();
	if((err = platform_driver_register(&dts_demo_driver))<0){
		LOG_ERR("platform_driver_register fail, err=%d\n", err);
		return err;
	}
	return 0;
}

static void __exit demo_exit(void)
{
	LOG_INF("enter");
	platform_driver_unregister(&dts_demo_driver);
	return;
}

module_init(demo_init);
module_exit(demo_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("tj<tj_wust@163.com>");